package LeetCode刷题;

/**
 * @program: Java_Study
 * @author: Xiaofan
 * @createTime: 2022-01-20 09:16
 * @description: Functions of this class is
 * 官方题解：（使用双指针）:
 *class Solution {
 *     public ListNode getKthFromEnd(ListNode head, int k) {
 *         ListNode fast = head;
 *         ListNode slow = head;
 *
 *         while (fast != null && k > 0) {//fast指针定位到k+1的位置上，然后和slow指针相隔k个节点，
 *             fast = fast.next;
 *             k--;
 *         }
 *         //然后当fast走到为空的时候，slow指针所指的就是倒数第k个元素
 *         while (fast != null) {
 *             fast = fast.next;
 *             slow = slow.next;
 *         }
 *
 *         return slow;
 *     }
 * }
 **/
public class NoNoNo链表中倒数第k个节点 {


    /**
     * public ListNode getKthFromEnd(ListNode head, int k) {
     *             int j=1;
     *             int length=1;
     *             ListNode p=head.next;
     *             while (p!=null){
     *                 length++;
     *                 p=p.next;
     *             }
     * //        System.out.println(length);
     *             while (head.next!=null){
     *                 if(j==length-k+1){
     *                     return head;
     *                 }
     *                 j++;
     *                 head=head.next;
     *             }
     *             return head;
     *         }
     */
}